
/*
===============================================================================
                    EntitySpaces Studio by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2012.1.0930.0
EntitySpaces Driver  : SQL
Date Generated       : 2016/3/21 1:39:12
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;



namespace yncTech.BusinessObjects
{
	/// <summary>
	/// Encapsulates the 'T_S_Functions' table
	/// </summary>

    [DebuggerDisplay("Data = {Debug}")]
	[Serializable]
	[DataContract]
	[KnownType(typeof(TSFunctions))]	
	[XmlType("TSFunctions")]
	public partial class TSFunctions : esTSFunctions
	{	
		[DebuggerBrowsable(DebuggerBrowsableState.RootHidden | DebuggerBrowsableState.Never)]
		protected override esEntityDebuggerView[] Debug
		{
			get { return base.Debug; }
		}

		override public esEntity CreateInstance()
		{
			return new TSFunctions();
		}
		
		#region Static Quick Access Methods
		static public void Delete(System.Decimal functionID)
		{
			var obj = new TSFunctions();
			obj.FunctionID = functionID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save();
		}

	    static public void Delete(System.Decimal functionID, esSqlAccessType sqlAccessType)
		{
			var obj = new TSFunctions();
			obj.FunctionID = functionID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
			obj.Save(sqlAccessType);
		}
		#endregion

		
					
		
	
	}



    [DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[CollectionDataContract]
	[XmlType("TSFunctionsCollection")]
	public partial class TSFunctionsCollection : esTSFunctionsCollection, IEnumerable<TSFunctions>
	{
		public TSFunctions FindByPrimaryKey(System.Decimal functionID)
		{
			return this.SingleOrDefault(e => e.FunctionID == functionID);
		}

		
		
		#region WCF Service Class
		
		[DataContract]
		[KnownType(typeof(TSFunctions))]
		public class TSFunctionsCollectionWCFPacket : esCollectionWCFPacket<TSFunctionsCollection>
		{
			public static implicit operator TSFunctionsCollection(TSFunctionsCollectionWCFPacket packet)
			{
				return packet.Collection;
			}

			public static implicit operator TSFunctionsCollectionWCFPacket(TSFunctionsCollection collection)
			{
				return new TSFunctionsCollectionWCFPacket() { Collection = collection };
			}
		}
		
		#endregion
		
				
	}



    [DebuggerDisplay("Query = {Parse()}")]
	[Serializable]	
	public partial class TSFunctionsQuery : esTSFunctionsQuery
	{
		public TSFunctionsQuery():this("TSFunctionsQuery")
		{
		}
		public TSFunctionsQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

		override protected string GetQueryName()
		{
			return "TSFunctionsQuery";
		}
		
					
	
		#region Explicit Casts
		
		public static explicit operator string(TSFunctionsQuery query)
		{
			return TSFunctionsQuery.SerializeHelper.ToXml(query);
		}

		public static explicit operator TSFunctionsQuery(string query)
		{
			return (TSFunctionsQuery)TSFunctionsQuery.SerializeHelper.FromXml(query, typeof(TSFunctionsQuery));
		}
		
		#endregion		
	}

	[DataContract]
	[Serializable]
	abstract public partial class esTSFunctions : esEntity
	{
		public esTSFunctions()
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Decimal functionID)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(functionID);
			else
				return LoadByPrimaryKeyStoredProcedure(functionID);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Decimal functionID)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(functionID);
			else
				return LoadByPrimaryKeyStoredProcedure(functionID);
		}

		private bool LoadByPrimaryKeyDynamic(System.Decimal functionID)
		{
			TSFunctionsQuery query = new TSFunctionsQuery();
			query.Where(query.FunctionID == functionID);
			return this.Load(query);
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Decimal functionID)
		{
			esParameters parms = new esParameters();
			parms.Add("FunctionID", functionID);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		#region Properties
		
		
		
		/// <summary>
		/// Maps to T_S_Functions.FunctionID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? FunctionID
		{
			get
			{
				return base.GetSystemDecimal(TSFunctionsMetadata.ColumnNames.FunctionID);
			}
			
			set
			{
				if(base.SetSystemDecimal(TSFunctionsMetadata.ColumnNames.FunctionID, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.SystemId
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? SystemId
		{
			get
			{
				return base.GetSystemDecimal(TSFunctionsMetadata.ColumnNames.SystemId);
			}
			
			set
			{
				if(base.SetSystemDecimal(TSFunctionsMetadata.ColumnNames.SystemId, value))
				{
					this._UpToTSSystemBySystemId = null;
					this.OnPropertyChanged("UpToTSSystemBySystemId");
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.SystemId);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.FunctionCode
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FunctionCode
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.FunctionCode);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.FunctionCode, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionCode);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.ParentID
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Decimal? ParentID
		{
			get
			{
				return base.GetSystemDecimal(TSFunctionsMetadata.ColumnNames.ParentID);
			}
			
			set
			{
				if(base.SetSystemDecimal(TSFunctionsMetadata.ColumnNames.ParentID, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.ParentID);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.FunctionName
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FunctionName
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.FunctionName);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.FunctionName, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionName);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.FunctionURL
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FunctionURL
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.FunctionURL);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.FunctionURL, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionURL);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.Sequence
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Int32? Sequence
		{
			get
			{
				return base.GetSystemInt32(TSFunctionsMetadata.ColumnNames.Sequence);
			}
			
			set
			{
				if(base.SetSystemInt32(TSFunctionsMetadata.ColumnNames.Sequence, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.Sequence);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.FunctionDesc
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String FunctionDesc
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.FunctionDesc);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.FunctionDesc, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionDesc);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.MapPath
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String MapPath
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.MapPath);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.MapPath, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.MapPath);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.IsActive
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.Boolean? IsActive
		{
			get
			{
				return base.GetSystemBoolean(TSFunctionsMetadata.ColumnNames.IsActive);
			}
			
			set
			{
				if(base.SetSystemBoolean(TSFunctionsMetadata.ColumnNames.IsActive, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.IsActive);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.CreatedBy
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String CreatedBy
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.CreatedBy);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.CreatedBy, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.CreatedBy);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.CreatedTime
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? CreatedTime
		{
			get
			{
				return base.GetSystemDateTime(TSFunctionsMetadata.ColumnNames.CreatedTime);
			}
			
			set
			{
				if(base.SetSystemDateTime(TSFunctionsMetadata.ColumnNames.CreatedTime, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.CreatedTime);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.LastUpdatedBy
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.String LastUpdatedBy
		{
			get
			{
				return base.GetSystemString(TSFunctionsMetadata.ColumnNames.LastUpdatedBy);
			}
			
			set
			{
				if(base.SetSystemString(TSFunctionsMetadata.ColumnNames.LastUpdatedBy, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.LastUpdatedBy);
				}
			}
		}		
		
		/// <summary>
		/// Maps to T_S_Functions.LastUpdatedTime
		/// </summary>
		[DataMember(EmitDefaultValue=false)]
		virtual public System.DateTime? LastUpdatedTime
		{
			get
			{
				return base.GetSystemDateTime(TSFunctionsMetadata.ColumnNames.LastUpdatedTime);
			}
			
			set
			{
				if(base.SetSystemDateTime(TSFunctionsMetadata.ColumnNames.LastUpdatedTime, value))
				{
					OnPropertyChanged(TSFunctionsMetadata.PropertyNames.LastUpdatedTime);
				}
			}
		}		
		
		[CLSCompliant(false)]
		internal protected TSSystem _UpToTSSystemBySystemId;
		#endregion	

		#region .str() Properties
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}
		
		public override void SetProperty(string name, object value)
		{
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "FunctionID": this.str().FunctionID = (string)value; break;							
						case "SystemId": this.str().SystemId = (string)value; break;							
						case "FunctionCode": this.str().FunctionCode = (string)value; break;							
						case "ParentID": this.str().ParentID = (string)value; break;							
						case "FunctionName": this.str().FunctionName = (string)value; break;							
						case "FunctionURL": this.str().FunctionURL = (string)value; break;							
						case "Sequence": this.str().Sequence = (string)value; break;							
						case "FunctionDesc": this.str().FunctionDesc = (string)value; break;							
						case "MapPath": this.str().MapPath = (string)value; break;							
						case "IsActive": this.str().IsActive = (string)value; break;							
						case "CreatedBy": this.str().CreatedBy = (string)value; break;							
						case "CreatedTime": this.str().CreatedTime = (string)value; break;							
						case "LastUpdatedBy": this.str().LastUpdatedBy = (string)value; break;							
						case "LastUpdatedTime": this.str().LastUpdatedTime = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "FunctionID":
						
							if (value == null || value is System.Decimal)
								this.FunctionID = (System.Decimal?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.FunctionID);
							break;
						
						case "SystemId":
						
							if (value == null || value is System.Decimal)
								this.SystemId = (System.Decimal?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.SystemId);
							break;
						
						case "ParentID":
						
							if (value == null || value is System.Decimal)
								this.ParentID = (System.Decimal?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.ParentID);
							break;
						
						case "Sequence":
						
							if (value == null || value is System.Int32)
								this.Sequence = (System.Int32?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.Sequence);
							break;
						
						case "IsActive":
						
							if (value == null || value is System.Boolean)
								this.IsActive = (System.Boolean?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.IsActive);
							break;
						
						case "CreatedTime":
						
							if (value == null || value is System.DateTime)
								this.CreatedTime = (System.DateTime?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.CreatedTime);
							break;
						
						case "LastUpdatedTime":
						
							if (value == null || value is System.DateTime)
								this.LastUpdatedTime = (System.DateTime?)value;
								OnPropertyChanged(TSFunctionsMetadata.PropertyNames.LastUpdatedTime);
							break;
					

						default:
							break;
					}
				}
			}
            else if (this.ContainsColumn(name))
            {
                this.SetColumn(name, value);
            }
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}		

		public esStrings str()
		{
			if (esstrings == null)
			{
				esstrings = new esStrings(this);
			}
			return esstrings;
		}

		sealed public class esStrings
		{
			public esStrings(esTSFunctions entity)
			{
				this.entity = entity;
			}
			
	
			public System.String FunctionID
			{
				get
				{
					System.Decimal? data = entity.FunctionID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionID = null;
					else entity.FunctionID = Convert.ToDecimal(value);
				}
			}
				
			public System.String SystemId
			{
				get
				{
					System.Decimal? data = entity.SystemId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.SystemId = null;
					else entity.SystemId = Convert.ToDecimal(value);
				}
			}
				
			public System.String FunctionCode
			{
				get
				{
					System.String data = entity.FunctionCode;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionCode = null;
					else entity.FunctionCode = Convert.ToString(value);
				}
			}
				
			public System.String ParentID
			{
				get
				{
					System.Decimal? data = entity.ParentID;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ParentID = null;
					else entity.ParentID = Convert.ToDecimal(value);
				}
			}
				
			public System.String FunctionName
			{
				get
				{
					System.String data = entity.FunctionName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionName = null;
					else entity.FunctionName = Convert.ToString(value);
				}
			}
				
			public System.String FunctionURL
			{
				get
				{
					System.String data = entity.FunctionURL;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionURL = null;
					else entity.FunctionURL = Convert.ToString(value);
				}
			}
				
			public System.String Sequence
			{
				get
				{
					System.Int32? data = entity.Sequence;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Sequence = null;
					else entity.Sequence = Convert.ToInt32(value);
				}
			}
				
			public System.String FunctionDesc
			{
				get
				{
					System.String data = entity.FunctionDesc;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FunctionDesc = null;
					else entity.FunctionDesc = Convert.ToString(value);
				}
			}
				
			public System.String MapPath
			{
				get
				{
					System.String data = entity.MapPath;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.MapPath = null;
					else entity.MapPath = Convert.ToString(value);
				}
			}
				
			public System.String IsActive
			{
				get
				{
					System.Boolean? data = entity.IsActive;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.IsActive = null;
					else entity.IsActive = Convert.ToBoolean(value);
				}
			}
				
			public System.String CreatedBy
			{
				get
				{
					System.String data = entity.CreatedBy;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedBy = null;
					else entity.CreatedBy = Convert.ToString(value);
				}
			}
				
			public System.String CreatedTime
			{
				get
				{
					System.DateTime? data = entity.CreatedTime;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedTime = null;
					else entity.CreatedTime = Convert.ToDateTime(value);
				}
			}
				
			public System.String LastUpdatedBy
			{
				get
				{
					System.String data = entity.LastUpdatedBy;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastUpdatedBy = null;
					else entity.LastUpdatedBy = Convert.ToString(value);
				}
			}
				
			public System.String LastUpdatedTime
			{
				get
				{
					System.DateTime? data = entity.LastUpdatedTime;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastUpdatedTime = null;
					else entity.LastUpdatedTime = Convert.ToDateTime(value);
				}
			}
			

			private esTSFunctions entity;
		}
		
		[NonSerialized]
		private esStrings esstrings;		
		
		#endregion
		
		#region Housekeeping methods

		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionsMetadata.Meta();
			}
		}

		#endregion		
		
		#region Query Logic

		public TSFunctionsQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new TSFunctionsQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(TSFunctionsQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return this.Query.Load();
		}
		
		protected void InitQuery(TSFunctionsQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntity)this).Connection;
			}			
		}

		#endregion
		
        [IgnoreDataMember]
		private TSFunctionsQuery query;		
	}



	[Serializable]
	abstract public partial class esTSFunctionsCollection : esEntityCollection<TSFunctions>
	{
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionsMetadata.Meta();
			}
		}

		protected override string GetCollectionName()
		{
			return "TSFunctionsCollection";
		}

		#endregion		
		
		#region Query Logic

	#if (!WindowsCE)
		[BrowsableAttribute(false)]
	#endif
		public TSFunctionsQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new TSFunctionsQuery();
					InitQuery(this.query);
				}

				return this.query;
			}
		}

		public bool Load(TSFunctionsQuery query)
		{
			this.query = query;
			InitQuery(this.query);
			return Query.Load();
		}

		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new TSFunctionsQuery();
				this.InitQuery(query);
			}
			return this.query;
		}

		protected void InitQuery(TSFunctionsQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			
			if (!query.es2.HasConnection)
			{
				query.es2.Connection = ((IEntityCollection)this).Connection;
			}			
		}

		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery((TSFunctionsQuery)query);
		}

		#endregion
		
		private TSFunctionsQuery query;
	}



	[Serializable]
	abstract public partial class esTSFunctionsQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return TSFunctionsMetadata.Meta();
			}
		}	
		
		#region QueryItemFromName
		
        protected override esQueryItem QueryItemFromName(string name)
        {
            switch (name)
            {
				case "FunctionID": return this.FunctionID;
				case "SystemId": return this.SystemId;
				case "FunctionCode": return this.FunctionCode;
				case "ParentID": return this.ParentID;
				case "FunctionName": return this.FunctionName;
				case "FunctionURL": return this.FunctionURL;
				case "Sequence": return this.Sequence;
				case "FunctionDesc": return this.FunctionDesc;
				case "MapPath": return this.MapPath;
				case "IsActive": return this.IsActive;
				case "CreatedBy": return this.CreatedBy;
				case "CreatedTime": return this.CreatedTime;
				case "LastUpdatedBy": return this.LastUpdatedBy;
				case "LastUpdatedTime": return this.LastUpdatedTime;

                default: return null;
            }
        }		
		
		#endregion
		
		#region esQueryItems

		public esQueryItem FunctionID
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.FunctionID, esSystemType.Decimal); }
		} 
		
		public esQueryItem SystemId
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.SystemId, esSystemType.Decimal); }
		} 
		
		public esQueryItem FunctionCode
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.FunctionCode, esSystemType.String); }
		} 
		
		public esQueryItem ParentID
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.ParentID, esSystemType.Decimal); }
		} 
		
		public esQueryItem FunctionName
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.FunctionName, esSystemType.String); }
		} 
		
		public esQueryItem FunctionURL
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.FunctionURL, esSystemType.String); }
		} 
		
		public esQueryItem Sequence
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.Sequence, esSystemType.Int32); }
		} 
		
		public esQueryItem FunctionDesc
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.FunctionDesc, esSystemType.String); }
		} 
		
		public esQueryItem MapPath
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.MapPath, esSystemType.String); }
		} 
		
		public esQueryItem IsActive
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.IsActive, esSystemType.Boolean); }
		} 
		
		public esQueryItem CreatedBy
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.CreatedBy, esSystemType.String); }
		} 
		
		public esQueryItem CreatedTime
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.CreatedTime, esSystemType.DateTime); }
		} 
		
		public esQueryItem LastUpdatedBy
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.LastUpdatedBy, esSystemType.String); }
		} 
		
		public esQueryItem LastUpdatedTime
		{
			get { return new esQueryItem(this, TSFunctionsMetadata.ColumnNames.LastUpdatedTime, esSystemType.DateTime); }
		} 
		
		#endregion
		
	}


	
	public partial class TSFunctions : esTSFunctions
	{

				
		#region TSFunctionHelp - One To One
		/// <summary>
		/// One to One
		/// Foreign Key Name - T_S_FunctionHelp_FunctionID_FK1
		/// </summary>

		[XmlIgnore]
		public TSFunctionHelp TSFunctionHelp
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._TSFunctionHelp == null)
				{
					this._TSFunctionHelp = new TSFunctionHelp();
					this._TSFunctionHelp.es.Connection.Name = this.es.Connection.Name;
					this.SetPostOneSave("TSFunctionHelp", this._TSFunctionHelp);
				
					if(this.FunctionID != null)
					{
						this._TSFunctionHelp.Query.Where(this._TSFunctionHelp.Query.FunctionID == this.FunctionID);
						this._TSFunctionHelp.Query.Load();
					}
				}

				return this._TSFunctionHelp;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._TSFunctionHelp != null) 
				{ 
					this.RemovePostOneSave("TSFunctionHelp"); 
					this._TSFunctionHelp = null;
					
				} 
			}          			
		}
		
		
		private TSFunctionHelp _TSFunctionHelp;
		#endregion

		#region UpToTSRoleCollection - Many To Many
		/// <summary>
		/// Many to Many
		/// Foreign Key Name - FK2_T_S_RoleFunctions_FunctionID
		/// </summary>

		[XmlIgnore]
		public TSRoleCollection UpToTSRoleCollection
		{
			get
			{
				if(this._UpToTSRoleCollection == null)
				{
					this._UpToTSRoleCollection = new TSRoleCollection();
					this._UpToTSRoleCollection.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("UpToTSRoleCollection", this._UpToTSRoleCollection);
					if (!this.es.IsLazyLoadDisabled && this.FunctionID != null)
					{
						TSRoleQuery m = new TSRoleQuery("m");
						TSRoleFunctionsQuery j = new TSRoleFunctionsQuery("j");
						m.Select(m);
						m.InnerJoin(j).On(m.RoleID == j.RoleID);
                        m.Where(j.FunctionID == this.FunctionID);

						this._UpToTSRoleCollection.Load(m);
					}
				}

				return this._UpToTSRoleCollection;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._UpToTSRoleCollection != null) 
				{ 
					this.RemovePostSave("UpToTSRoleCollection"); 
					this._UpToTSRoleCollection = null;
					
				} 
			}  			
		}

		/// <summary>
		/// Many to Many Associate
		/// Foreign Key Name - FK2_T_S_RoleFunctions_FunctionID
		/// </summary>
		public void AssociateTSRoleCollection(TSRole entity)
		{
			if (this._TSRoleFunctionsCollection == null)
			{
				this._TSRoleFunctionsCollection = new TSRoleFunctionsCollection();
				this._TSRoleFunctionsCollection.es.Connection.Name = this.es.Connection.Name;
				this.SetPostSave("TSRoleFunctionsCollection", this._TSRoleFunctionsCollection);
			}

			TSRoleFunctions obj = this._TSRoleFunctionsCollection.AddNew();
			obj.FunctionID = this.FunctionID;
			obj.RoleID = entity.RoleID;
		}

		/// <summary>
		/// Many to Many Dissociate
		/// Foreign Key Name - FK2_T_S_RoleFunctions_FunctionID
		/// </summary>
		public void DissociateTSRoleCollection(TSRole entity)
		{
			if (this._TSRoleFunctionsCollection == null)
			{
				this._TSRoleFunctionsCollection = new TSRoleFunctionsCollection();
				this._TSRoleFunctionsCollection.es.Connection.Name = this.es.Connection.Name;
				this.SetPostSave("TSRoleFunctionsCollection", this._TSRoleFunctionsCollection);
			}

			TSRoleFunctions obj = this._TSRoleFunctionsCollection.AddNew();
			obj.FunctionID = this.FunctionID;
            obj.RoleID = entity.RoleID;
			obj.AcceptChanges();
			obj.MarkAsDeleted();
		}

		private TSRoleCollection _UpToTSRoleCollection;
		private TSRoleFunctionsCollection _TSRoleFunctionsCollection;
		#endregion

		#region TSRoleFunctionsCollectionByFunctionID - Zero To Many
		
		static public esPrefetchMap Prefetch_TSRoleFunctionsCollectionByFunctionID
		{
			get
			{
				esPrefetchMap map = new esPrefetchMap();
				map.PrefetchDelegate = yncTech.BusinessObjects.TSFunctions.TSRoleFunctionsCollectionByFunctionID_Delegate;
				map.PropertyName = "TSRoleFunctionsCollectionByFunctionID";
				map.MyColumnName = "FunctionID";
				map.ParentColumnName = "FunctionID";
				map.IsMultiPartKey = false;
				return map;
			}
		}		
		
		static private void TSRoleFunctionsCollectionByFunctionID_Delegate(esPrefetchParameters data)
		{
			TSFunctionsQuery parent = new TSFunctionsQuery(data.NextAlias());

			TSRoleFunctionsQuery me = data.You != null ? data.You as TSRoleFunctionsQuery : new TSRoleFunctionsQuery(data.NextAlias());

			if (data.Root == null)
			{
				data.Root = me;
			}
			
			data.Root.InnerJoin(parent).On(parent.FunctionID == me.FunctionID);

			data.You = parent;
		}			
		
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK2_T_S_RoleFunctions_FunctionID
		/// </summary>

		[XmlIgnore]
		public TSRoleFunctionsCollection TSRoleFunctionsCollectionByFunctionID
		{
			get
			{
				if(this._TSRoleFunctionsCollectionByFunctionID == null)
				{
					this._TSRoleFunctionsCollectionByFunctionID = new TSRoleFunctionsCollection();
					this._TSRoleFunctionsCollectionByFunctionID.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("TSRoleFunctionsCollectionByFunctionID", this._TSRoleFunctionsCollectionByFunctionID);
				
					if (this.FunctionID != null)
					{
						if (!this.es.IsLazyLoadDisabled)
						{
							this._TSRoleFunctionsCollectionByFunctionID.Query.Where(this._TSRoleFunctionsCollectionByFunctionID.Query.FunctionID == this.FunctionID);
							this._TSRoleFunctionsCollectionByFunctionID.Query.Load();
						}

						// Auto-hookup Foreign Keys
						this._TSRoleFunctionsCollectionByFunctionID.fks.Add(TSRoleFunctionsMetadata.ColumnNames.FunctionID, this.FunctionID);
					}
				}

				return this._TSRoleFunctionsCollectionByFunctionID;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._TSRoleFunctionsCollectionByFunctionID != null) 
				{ 
					this.RemovePostSave("TSRoleFunctionsCollectionByFunctionID"); 
					this._TSRoleFunctionsCollectionByFunctionID = null;
					
				} 
			} 			
		}
			
		
		private TSRoleFunctionsCollection _TSRoleFunctionsCollectionByFunctionID;
		#endregion

				
		#region UpToTSSystemBySystemId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - T_S_Functions_FK1
		/// </summary>

		[XmlIgnore]
					
		public TSSystem UpToTSSystemBySystemId
		{
			get
			{
				if (this.es.IsLazyLoadDisabled) return null;
				
				if(this._UpToTSSystemBySystemId == null && SystemId != null)
				{
					this._UpToTSSystemBySystemId = new TSSystem();
					this._UpToTSSystemBySystemId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToTSSystemBySystemId", this._UpToTSSystemBySystemId);
					this._UpToTSSystemBySystemId.Query.Where(this._UpToTSSystemBySystemId.Query.SystemId == this.SystemId);
					this._UpToTSSystemBySystemId.Query.Load();
				}	
				return this._UpToTSSystemBySystemId;
			}
			
			set
			{
				this.RemovePreSave("UpToTSSystemBySystemId");
				

				if(value == null)
				{
					this.SystemId = null;
					this._UpToTSSystemBySystemId = null;
				}
				else
				{
					this.SystemId = value.SystemId;
					this._UpToTSSystemBySystemId = value;
					this.SetPreSave("UpToTSSystemBySystemId", this._UpToTSSystemBySystemId);
				}
				
			}
		}
		#endregion
		

		
		protected override esEntityCollectionBase CreateCollectionForPrefetch(string name)
		{
			esEntityCollectionBase coll = null;

			switch (name)
			{
				case "TSRoleFunctionsCollectionByFunctionID":
					coll = this.TSRoleFunctionsCollectionByFunctionID;
					break;	
			}

			return coll;
		}		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "TSRoleFunctionsCollectionByFunctionID", typeof(TSRoleFunctionsCollection), new TSRoleFunctions()));
		
			return props;
		}
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
			if(!this.es.IsDeleted && this._UpToTSSystemBySystemId != null)
			{
				this.SystemId = this._UpToTSSystemBySystemId.SystemId;
			}
		}
		
		/// <summary>
		/// Called by ApplyPostSaveKeys 
		/// </summary>
		/// <param name="coll">The collection to enumerate over</param>
		/// <param name="key">"The column name</param>
		/// <param name="value">The column value</param>
		private void Apply(esEntityCollectionBase coll, string key, object value)
		{
			foreach (esEntity obj in coll)
			{
				if (obj.es.IsAdded)
				{
					obj.SetProperty(key, value);
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._TSRoleFunctionsCollection != null)
			{
				Apply(this._TSRoleFunctionsCollection, "FunctionID", this.FunctionID);
			}
			if(this._TSRoleFunctionsCollectionByFunctionID != null)
			{
				Apply(this._TSRoleFunctionsCollectionByFunctionID, "FunctionID", this.FunctionID);
			}
		}
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostOneToOneSave.
		/// </summary>
		protected override void ApplyPostOneSaveKeys()
		{
			if(this._TSFunctionHelp != null)
			{
				if(this._TSFunctionHelp.es.IsAdded)
				{
					this._TSFunctionHelp.FunctionID = this.FunctionID;
				}
			}
		}
		
	}
	



	[Serializable]
	public partial class TSFunctionsMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected TSFunctionsMetadata()
		{
			m_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.FunctionID, 0, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.FunctionID;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 18;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.SystemId, 1, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.SystemId;
			c.NumericPrecision = 18;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.FunctionCode, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.FunctionCode;
			c.CharacterMaxLength = 20;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.ParentID, 3, typeof(System.Decimal), esSystemType.Decimal);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.ParentID;
			c.NumericPrecision = 18;
			c.HasDefault = true;
			c.Default = @"((-1))";
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.FunctionName, 4, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.FunctionName;
			c.CharacterMaxLength = 50;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.FunctionURL, 5, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.FunctionURL;
			c.CharacterMaxLength = 150;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.Sequence, 6, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.Sequence;
			c.NumericPrecision = 10;
			c.HasDefault = true;
			c.Default = @"((0))";
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.FunctionDesc, 7, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.FunctionDesc;
			c.CharacterMaxLength = 200;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.MapPath, 8, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.MapPath;
			c.CharacterMaxLength = 20;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.IsActive, 9, typeof(System.Boolean), esSystemType.Boolean);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.IsActive;
			c.IsNullable = true;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.CreatedBy, 10, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.CreatedBy;
			c.CharacterMaxLength = 40;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.CreatedTime, 11, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.CreatedTime;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.LastUpdatedBy, 12, typeof(System.String), esSystemType.String);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.LastUpdatedBy;
			c.CharacterMaxLength = 40;
			m_columns.Add(c);
				
			c = new esColumnMetadata(TSFunctionsMetadata.ColumnNames.LastUpdatedTime, 13, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = TSFunctionsMetadata.PropertyNames.LastUpdatedTime;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			m_columns.Add(c);
				
		}
		#endregion	
	
		static public TSFunctionsMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base.m_dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base.m_columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string FunctionID = "FunctionID";
			 public const string SystemId = "SystemId";
			 public const string FunctionCode = "FunctionCode";
			 public const string ParentID = "ParentID";
			 public const string FunctionName = "FunctionName";
			 public const string FunctionURL = "FunctionURL";
			 public const string Sequence = "Sequence";
			 public const string FunctionDesc = "FunctionDesc";
			 public const string MapPath = "MapPath";
			 public const string IsActive = "IsActive";
			 public const string CreatedBy = "CreatedBy";
			 public const string CreatedTime = "CreatedTime";
			 public const string LastUpdatedBy = "LastUpdatedBy";
			 public const string LastUpdatedTime = "LastUpdatedTime";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string FunctionID = "FunctionID";
			 public const string SystemId = "SystemId";
			 public const string FunctionCode = "FunctionCode";
			 public const string ParentID = "ParentID";
			 public const string FunctionName = "FunctionName";
			 public const string FunctionURL = "FunctionURL";
			 public const string Sequence = "Sequence";
			 public const string FunctionDesc = "FunctionDesc";
			 public const string MapPath = "MapPath";
			 public const string IsActive = "IsActive";
			 public const string CreatedBy = "CreatedBy";
			 public const string CreatedTime = "CreatedTime";
			 public const string LastUpdatedBy = "LastUpdatedBy";
			 public const string LastUpdatedTime = "LastUpdatedTime";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(TSFunctionsMetadata))
			{
				if(TSFunctionsMetadata.mapDelegates == null)
				{
					TSFunctionsMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (TSFunctionsMetadata.meta == null)
				{
					TSFunctionsMetadata.meta = new TSFunctionsMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!m_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();			


				meta.AddTypeMap("FunctionID", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("SystemId", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("FunctionCode", new esTypeMap("char", "System.String"));
				meta.AddTypeMap("ParentID", new esTypeMap("numeric", "System.Decimal"));
				meta.AddTypeMap("FunctionName", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("FunctionURL", new esTypeMap("char", "System.String"));
				meta.AddTypeMap("Sequence", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("FunctionDesc", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("MapPath", new esTypeMap("char", "System.String"));
				meta.AddTypeMap("IsActive", new esTypeMap("bit", "System.Boolean"));
				meta.AddTypeMap("CreatedBy", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("CreatedTime", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("LastUpdatedBy", new esTypeMap("varchar", "System.String"));
				meta.AddTypeMap("LastUpdatedTime", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				meta.Source = "T_S_Functions";
				meta.Destination = "T_S_Functions";
				
				meta.spInsert = "proc_T_S_FunctionsInsert";				
				meta.spUpdate = "proc_T_S_FunctionsUpdate";		
				meta.spDelete = "proc_T_S_FunctionsDelete";
				meta.spLoadAll = "proc_T_S_FunctionsLoadAll";
				meta.spLoadByPrimaryKey = "proc_T_S_FunctionsLoadByPrimaryKey";
				
				this.m_providerMetadataMaps["esDefault"] = meta;
			}
			
			return this.m_providerMetadataMaps["esDefault"];
		}

		#endregion

		static private TSFunctionsMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
